//高精度加减法
#include <stdio.h>
#include <string.h>

int swap( char *a )	//将数反向排序，便于进位操作
{
	int i=0,length;
	char process[1000];
	length = strlen(a);
	for ( i=0 ; i<=length-1 ; i++ )
	{
		process[length-i-1] = a[i];
	}
	for ( i=0 ; i<=length-1 ; i++ )
	{
		a[i] = process[i];
	}
}

void char_to_int( char *a , int *b )	//将char型转换为int型
{
	int i=0 , length;
	length = strlen( a );
	for ( i=0 ; i<=length-1 ; i++ )
	{
		b[i] = a[i] - '0';
	}
}

void plus( int length , int *c , int *d , int *e )	//加法运算
{
	
	for ( int i=0 ; i<=length ; i++ )
	{
		e[i] = c[i] + d[i];
		if ( e[i] > 10 )
		{
			e[i+1] = e[i+1] + 1;
			e[i] = e[i] - 10;
		}
	}
}

void substract( int length , int *c , int *d , int *e )	//减法运算
{
	for ( int i=0 ; i<=length ; i++ )
	{
		e[i] = c[i] - d[i];
		if ( e[i] < 0 )
		{
			e[i+1] = e[i+1] - 1;
			e[i] += 10;
		}
	}
	
}

int main()
{
	int n,j=0,k=0,length1,length2,length;//n用于输入计算次数,j,k用于读入
	char input1[1000],input2[1000],process[1000],pool;
	int calculate1[1000],calculate2[1000],output[1000],flag=0;
	memset ( calculate1 , 0 , sizeof(calculate1) );
	memset ( calculate2 , 0 , sizeof(calculate2) );
	scanf("%d",&n);
	for ( int i=1 ; i<=n ; i++)
	{
		//读入数组
		do
		{
			input1[j]=getchar();
			j++;
		}while ( input1[j] != '+' && input1[j] != '-' );
		pool=getchar();
		do
		{
			input2[k]=getchar();
			k++;
		}while ( ( input2[k] = getchar() ) != EOF );
		
		//判断数组长度
		length1 = strlen(input1);
		length2 = strlen(input2);
		if ( length1 >= length2 )
		{
			length = length1;
		}
		else
		{
			length = length2;
		}
		
		//转化和计算数组
		swap( input1 );
		swap( input2 );
		if ( pool = '+' )
		{
			plus ( length , calculate1 , calculate2 , output );
			
		}
		if ( pool = '-')
		{
			if (  length1 > length2 ||  strcmp(input1,input2) < 0 && length1 == length2 )
			{
				flag=1;
				substract( length , calculate2 , calculate1 , output );
			}
			else
			{
				substract( length , calculate1 , calculate2 , output );
			}
		}
		
		//打印数组
		while ( output[ length - 1 ] == 0 && length > 1 )
		{
			length--;
		}
		if ( flag==1 )
		{
			printf("-");
		}
		for ( int i=length-1 ; i >= 0 ; i--)
		{
			printf("%d",output[i]);
		}
		printf("\n");
	}
	return 0;
}

